<?php

include_once("{$_SERVER['DOCUMENT_ROOT']}/header.php");
include_once(PHP_ROOT . "/class/db/bbs/BbsListManager.php");

//오버라이딩
class CList extends BbsListManager {

    function cate_list() {
        $list.="<select class='w_200 h_20' id='" . $this->layer_id . "_cate' onChange=\"bbs.cateChange(this);\"> <option value='0'>-----이동할 카테고리-----</option>";
        $sql = "select* from tb_board_division";
        $r = $this->get_result($sql);
        while ($result = $r->fetch_assoc()) {
            $list.= "<option value='{$result['board_table']}'>{$result['board_description']}</option>";
        }
        $list.="</select>";
        return $list;
    }

    function set_style() {
        global $SESSION_ALL_EXCUTE;

        $_F = new Func();
        $token = $_F->makeToken($SESSION_ALL_EXCUTE);
        global $FOLDER_PATH;
        global $BBS_PATH;
        global $PAGE_ALL_DEL_OK;
        global $PAGE_ALL_MOVE_OK;
        global $PAGE_LIST;
        global $FOLDER_PATH_PHP;
        $odd = 1;
        $cate_list = $this->cate_list();
        $admin = "
                    <tr >
                         <td class='left w_50' bgcolor='#ffffff'>
                        <input  type='checkbox' class='all_check_box' onClick=\"bbs.all_check_box('$this->layer_id',this);\"> *
                        </td>
                        <td colspan='100' bgcolor='#ffffff' style=\"text-align:left; \">
                            <input type='button' class='h_20' value='삭제' onClick=\"bbs.allExcute('$PAGE_ALL_DEL_OK','$this->layer_id','$token');\">
                            <input type='button'  class='h_20' value='이동' onClick=\"bbs.allExcuteMove('$PAGE_ALL_MOVE_OK',$('#" . $this->layer_id . "_cate').val(),'$this->layer_id','$token');\">
                            $cate_list
                            <select class='h_20'  id='listCount' title='보여질 리스트숫자' onChange=\"var l = $(this).val();bbs.swapPage('$PAGE_LIST&num='+l,'$this->layer_id');\" > 
                            <option value='10'>10줄</option>
                            <option value='15'>15줄</option>
                            <option value='20'>20줄</option>
                            <option value='30'>30줄</option>
                            <option value='50'>50줄</option>
                            <option value='100'>100줄</option>
                            <option value='1000'>1000줄</option>
                            <option value='10000'>10000줄</option>
                            </selcet>
                         </td>
                    </tr>";
        if ($this->getAdmin() == true) {
            echo"$admin";
        }
        while ($result = $this->result->fetch_object()) {

            $sql = "select user_level from tb_users where user_num = '{$result->user_num}'";
            // $user = $this->db->query($sql);
            $user = $this->db->query($sql)->fetch_assoc();
            if (!$user['user_level']) {
                $user['user_level'] = 0;
            }
            $user_img = "<div><img src='/noritu/img/level_{$user['user_level']}.png'></div>";


            //관리자모드일때 체크박스표시
            if ($this->getAdmin() == true) {
                $all_check_box = "<input type='checkbox'  value='$result->uid'>";
            } else {
                $all_check_box = "";
            }
            //홀수짝수구분해서 색지정
            if ($odd % 2 == 0) {
                $line_color = "#E5E5E5";
            } else {
                $line_color = "";
            }
            //댓글이면 공백문자 추가
            for ($i = 0; $i < $result->depth; $i++) {
                $depth .="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
            }
            if ($i > 0) {
                $depth .="<img src='" . SCRIPT_ROOT . "/img/icon/re.gif' border='0'style=\"width:8px; height:8px;\" align='absmiddle'>";
            }
            //글자 길이 제한

            $name_tmp = $_F->cutStringByUtf8($result->user_nick, 12, true, ''); //인자가 홀수일때 한글이 안깨짐
            $title = $_F->cutStringByUtf8($result->board_subject, 60, true, '');
            $date = $_F->getDateFormat($result->reg_date, 1);

            $name = "<div  class='hand'  onClick=\"bbs.loadMenu('member_info','{$FOLDER_PATH}/user_info.php?user_num={$result->user_num}','300','180',$(this).offset());\">$name_tmp</div>";

            //비로그인 글쓰기 하면 
            if (!$result->user_num) {
                $name = "<div style=\"color:gray;\">$name_tmp</div>";
                $user_img = "";
            }

            // 코멘트 숫자
            $comment_list = $this->get_count("tb_board_comment", "where buid = '$result->uid' and user_deleted ='0'");
            if ($comment_list) {
                $comment_list = "[<span style='color:red;'>$comment_list</span>]";
            } else {
                $comment_list = "";
            }

            //파일유무
            $file_list = $this->get_count("tb_image_upload", "where board_id = '$result->uid' ", "upload_id");
            if ($file_list) {
                $file_list = "<img src='" . SCRIPT_ROOT . "/img/icon/save.png' border='0' width='16' height='16' align='absmiddle'>";
            } else {
                $file_list = "";
            }
            //시간계산
            $now = date("Y-m-d H:i:s");
            $end = $result->reg_date;
            $time = strtotime($now) - strtotime($end);
            $mm = ceil($time / 60);
            $h=0;
            $m = ceil($mm % 60);


            if ($time >= 3600) {
                $h = ceil($time / 3600);
            } else {
                $h = 0;
            }


            //24시간 안된글
            if ($h >= 24) {

                $new_list = "";
            } else {
                if ($h > 0) {
                    $htime = "$h 시간";
                } else {
                    $htime = "";
                }
                $date = "<span style='color:red'>$htime $m 분 </span>전";
                $new_list = "<img src='/noritu/img/new_icon2.png' align='absmiddle'>";
            }




            $subject = "<a class='hand' onClick=\"bbs.swapPage('$BBS_PATH?bbs_mode=view&page=$this->page&key_search=$this->key_search&key_search_field=$this->key_search_field&bbs_uid=$result->uid&layer_id=$this->layer_id&category=$this->category&num=$this->end_no&order_by=$this->order_by','$this->layer_id');\">$title $file_list $comment_list $new_list</a>";


            //오버라이딩 구역 시작
            echo("
					<tr>
                                        <td class='h_30 left c_$result->uid' bgcolor='$line_color' > $all_check_box  </td>
					<td class='left gray'  bgcolor='$line_color' > $result->ord_num </td>
					<td class='left' bgcolor='$line_color'  > $subject </td>
					<td class='left' bgcolor='$line_color' >$user_img $name </td>
					<td class='left gray' bgcolor='$line_color' >$date </td>
					<td class='center' bgcolor='$line_color' >$result->read_count</td>
                                        <td class='center' bgcolor='$line_color' >$result->agree_count</td>
					</tr>
					");
            //오버라이딩 구역 끝
            $depth = "";
            $odd++;
        }
    }

    function set_search() {

        global $db;
        global $FOLDER_PATH;
        global $BBS_PATH;
        global $PAGE_SEARCH;
        //오버라이딩 구역 시작
        $this->search = "
		<form id='searchForm_$this->layer_id'>
		<table class='bbs'>
		<tr>
		<td>
                <span class='select'>
		<select class='key_search_field' name='key_search_field'>
		<option value='ord_num'>번호</option>
		<option value='user_nick'>작성자</option>
		<option value='board_subject'>제목</option>
		<option value='board_content'>내용</option>
		</select>
		</span>
		</td>
		<td>
                <input type='text' class='key_search' name='key_search' value='$this->key_search' class='bbs_input' onmouseover=\"bbs.getFocus(this);\"> 
		<input type='image' value='검색' src='$FOLDER_PATH/img/bt_search.gif' align='absmiddle' 
		onClick=\"bbs.search('searchForm_$this->layer_id','$PAGE_SEARCH&table=$this->table&page=$this->page&layer_id=$this->layer_id&category=$this->category&num=$this->end_no&order_by=$this->order_by','$this->layer_id'); return false \" >
                </td>
		</tr>
		</table>
		</form>
                <script>
                if($('.key_search').val()!=''){
                $('.key_search_field').val('$this->key_search_field');
                    }
                    </script>
		";
        //오버라이딩 구역 끝
        echo "$this->search";
    }

}

